package cn.com.smartdevices.bracelet.chart.util;

import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.dataprocess.DaySportData;
import com.goodving.guli.bt.dataprocess.SleepInfo;
import com.goodving.guli.bt.dataprocess.SportDay;
import com.goodving.guli.bt.dataprocess.StepsInfo;
import com.goodving.guli.bt.model.C1981P;
import com.goodving.guli.bt.model.DataManager;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.model.UserSleepModify;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.view.BitmapDescriptorFactory;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

/* renamed from: cn.com.smartdevices.bracelet.chart.util.r */
public class DynamicData { // C0802r
    private static final String f4096a = "DynamicData";
    private static DynamicData mDynamicData; // f4097z
    private int f4098b;
    private int f4099c;
    private int f4100d;
    private int f4101e;
    private String f4102f;
    private int f4103g;
    private int f4104h;
    private Date f4105i;
    private Date f4106j;
    private String f4107k;
    private boolean f4108l;
    private float f4109m;
    private float f4110n;
    private float f4111o;
    private String f4112p;
    private float f4113q;
    private String f4114r;
    private int f4115s;
    private C1981P f4116t;
    private int f4117u;
    private int f4118v;
    private int f4119w;
    private HashMap<String, UserSleepModify> f4120x;
    private boolean f4121y;

    private DynamicData() {
        this.f4108l = true;
        this.f4115s = -1;
        this.f4117u = 20;
        this.f4118v = 1;
        this.f4121y = false;
        this.f4120x = new HashMap();
    }

    public static DynamicData getInstance() {  //m8771a
        if (mDynamicData == null) {
            mDynamicData = new DynamicData();
        }
        return mDynamicData;
    }

    public UserSleepModify m8772a(SportDay sportDay) {
        String key = sportDay.getKey();
        if (this.f4120x.containsKey(key)) {
            return (UserSleepModify) this.f4120x.get(key);
        }
        DataManager a = DataManager.m12179a();
        DaySportData.Summary b = a.m12210b(sportDay);
        UserSleepModify userSleepModify = new UserSleepModify();
        if (b == null) {
            return userSleepModify;
        }
        userSleepModify.sleepStart = b.getUserSleepStart();
        userSleepModify.sleepEnd = b.getUserSleepEnd();
        m8777a(sportDay, userSleepModify);
        a.m12220d(sportDay);
        return userSleepModify;
    }

    public void m8773a(float f) {
        this.f4109m = f;
    }

    public void m8774a(int i) {
        this.f4098b = i;
    }

    public void m8775a(int i, int i2) {
        GuliLog.tracePrintInfo(f4096a, "Update StepInfo With Realtime Steps : " + i);
        DataManager a = DataManager.m12179a();
        SportDay d = a.m12219d(i2);
        if (d != null) {
            float f;
            int i3;
            int i4;
            int i5;
            GuliLog.tracePrintInfo(f4096a, "Current Step Day : " + Utils.m8050c(d));
            long j = 0;
            SportDay sportDay = null;
            if (this.f4121y) {
                long readRealtimeStepsTimestamp = Keeper.readRealtimeStepsTimestamp(i2);
                if (readRealtimeStepsTimestamp == -1) {
                    readRealtimeStepsTimestamp = 0;
                }
                Calendar instance = Calendar.getInstance();
                instance.setTimeInMillis(readRealtimeStepsTimestamp);
                SportDay sportDay2 = new SportDay(instance);
                if (!sportDay2.equals(d)) {
                    i = -1;
                    Keeper.keepRealtimeSteps(i2, -1);
                } else if (i == -1) {
                    i = Keeper.readRealtimeSteps(i2);
                }
                GuliLog.tracePrintInfo(f4096a, "Restored/Reseted Realtime Steps : " + i);
                SportDay sportDay3 = sportDay2;
                j = readRealtimeStepsTimestamp;
                sportDay = sportDay3;
            }
            DaySportData b = a.m12211b(i2, d);
            StepsInfo stepsInfo = null;
            if (b != null) {
                stepsInfo = b.getStepsInfo();
            }
            if (stepsInfo == null) {
                stepsInfo = new StepsInfo();
            }
            int stepsCount = stepsInfo.getStepsCount();
            int distance = stepsInfo.getDistance();
            int calories = stepsInfo.getCalories();
            GuliLog.tracePrintInfo(f4096a, "Origin StepInfo : " + stepsCount + " , " + distance + " , " + calories);
            Object obj = !this.f4121y ? 1 : null;
            if (this.f4121y && i > stepsCount) {
                long readSyncTime = Keeper.readSyncTime(i2);
                if (readSyncTime == -1) {
                    readSyncTime = 0;
                }
                Calendar instance2 = Calendar.getInstance();
                instance2.setTimeInMillis(readSyncTime);
                if (sportDay.equals(new SportDay(instance2))) {
                    f = (((float) ((j - readSyncTime) / 1000)) / BitmapDescriptorFactory.HUE_YELLOW) + 1.0f;
                    GuliLog.tracePrintInfo(f4096a, "RealtimeSteps : " + j + ", StepInfo : " + readSyncTime + ", Offset : " + f + " Mins");
                } else {
                    f = 1.0f;
                }
                if (((float) (i - stepsCount)) < f * 512.0f) {
                    obj = 1;
                }
            }
            if (obj != null) {
                i3 = stepsCount < 0 ? 0 : stepsCount;
                i4 = i <= 0 ? i3 : i;
                if (i3 > 0) {
                    f = ((float) i4) / ((float) i3);
                    i5 = (int) (((float) distance) * f);
                    i3 = (int) (f * ((float) calories));
                } else {
                    PersonInfo readPersonInfo = Keeper.readPersonInfo();
                    double d2 = (readPersonInfo == null || readPersonInfo.height <= 0) ? 0.714d : (((double) readPersonInfo.height) * 0.42d) / 100.0d;
                    i5 = (int) (d2 * ((double) i4));
                    i3 = (int) ((((((double) readPersonInfo.weight) * 2.2046d) * 1.19d) * ((double) i4)) / 4000.0d);
                }
                GuliLog.tracePrintInfo(f4096a, "Realtime StepInfo : " + i4 + " , " + i5 + " , " + i3);
            } else {
                i3 = calories;
                i5 = distance;
                i4 = stepsCount;
            }
            m8774a(i4);
            m8783b(i5);
            m8793d(i3);
        }
    }

    public void m8776a(C1981P c1981p) {
        this.f4116t = c1981p;
    }

    public void m8777a(SportDay sportDay, UserSleepModify userSleepModify) {
        this.f4120x.put(sportDay.getKey(), userSleepModify);
    }

    public void m8778a(String str) {
        this.f4102f = str;
    }

    public void m8779a(Date date) {
        this.f4105i = date;
    }

    public void m8780a(boolean z) {
        this.f4108l = z;
    }

    public C1981P m8781b() {
        return this.f4116t;
    }

    public void m8782b(float f) {
        this.f4110n = f;
    }

    public void m8783b(int i) {
        this.f4099c = i;
    }

    public void m8784b(String str) {
        this.f4107k = str;
    }

    public void m8785b(Date date) {
        this.f4106j = date;
    }

    public void m8786b(boolean z) {
        this.f4121y = z;
    }

    public int m8787c() {
        return this.f4098b;
    }

    public void m8788c(float f) {
        this.f4111o = f;
    }

    public void m8789c(int i) {
        this.f4100d = i;
    }

    public void m8790c(String str) {
        this.f4112p = str;
    }

    public int m8791d() {
        return this.f4099c;
    }

    public void m8792d(float f) {
        this.f4113q = f;
    }

    public void m8793d(int i) {
        this.f4101e = i;
    }

    public void m8794d(String str) {
        this.f4114r = str;
    }

    public int m8795e() {
        return this.f4100d;
    }

    public void m8796e(int i) {
        this.f4103g = i;
    }

    public int m8797f() {
        return this.f4101e;
    }

    public void m8798f(int i) {
        this.f4104h = i;
    }

    public String m8799g() {
        return this.f4102f;
    }

    public void m8800g(int i) {
        this.f4115s = i;
    }

    public int m8801h() {
        return this.f4103g;
    }

    public void m8802h(int i) {
        this.f4119w = i;
    }

    public int m8803i() {
        return this.f4104h;
    }

    public void m8804i(int i) {
        this.f4117u = i;
    }

    public Date m8805j() {
        return this.f4105i;
    }

    public void m8806j(int i) {
        this.f4118v = i;
    }

    public Date m8807k() {
        return this.f4106j;
    }

    public String m8808l() {
        return this.f4107k;
    }

    public boolean m8809m() {
        return this.f4108l;
    }

    public float m8810n() {
        return this.f4109m;
    }

    public float m8811o() {
        return this.f4110n;
    }

    public float m8812p() {
        return this.f4111o;
    }

    public String m8813q() {
        return this.f4112p;
    }

    public float m8814r() {
        return this.f4113q;
    }

    public String m8815s() {
        return this.f4114r;
    }

    public int m8816t() {
        return this.f4115s;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("StepCount : " + this.f4098b);
        stringBuilder.append(", StepDistance : " + this.f4099c);
        stringBuilder.append(", LiningDistance : " + this.f4100d);
        stringBuilder.append(", StepCalorie : " + this.f4101e);
        stringBuilder.append(", SleepTime : " + this.f4103g);
        stringBuilder.append(", SleepDeepTime : " + this.f4104h);
        stringBuilder.append("\nWeight : ").append(this.f4109m).append("\nWeightBMI : ").append(this.f4113q).append("\nWeightTip : " + this.f4114r);
        return stringBuilder.toString();
    }

    public int m8817u() {
        return this.f4119w;
    }

    public int m8818v() {
        return this.f4117u;
    }

    public int m8819w() {
        return this.f4118v;
    }

    public boolean m8820x() {
        return this.f4121y;
    }

    public void m8821y() {
        DataManager a = DataManager.m12179a();
        SportDay n = a.m9057n();
        if (n != null) {
            boolean z;
            SleepInfo sleepInfo;
            GuliLog.tracePrintInfo(f4096a, "Current Sleep Day : " + Utils.m8050c(n));
            DaySportData g = a.m9052g(n);
            SleepInfo sleepInfo2 = null;
            if (g != null) {
                sleepInfo2 = g.getSleepInfo();
            }
            if (sleepInfo2 == null) {
                sleepInfo2 = new SleepInfo();
                z = true;
            } else {
                z = sleepInfo2.getSleepCount() == 0;
            }
            if (z && n.calendar.get(Calendar.HOUR_OF_DAY) >= 5) {
                z = false;
            }
            GuliLog.tracePrintInfo(f4096a, "Show Previous Day's Sleep Info: " + z);
            if (z) {
                a.m9053i(n.addDay(-1));
                g = a.m9052g(n.addDay(-1));
                if (g != null) {
                    sleepInfo = g.getSleepInfo();
                    if (sleepInfo == null) {
                        sleepInfo = new SleepInfo();
                    }
                    if (sleepInfo.getHasSleep() && sleepInfo.getNosleepReason() == SleepInfo.NOSLEEP_NONWEAR) {
                        m8780a(false);
                    } else {
                        m8780a(true);
                    }
                    m8796e(sleepInfo.getSleepCount());
                    m8798f(sleepInfo.getNonRemCount());
                    m8779a(sleepInfo.getStartDate());
                    m8785b(sleepInfo.getStopDate());
                }
            }
            sleepInfo = sleepInfo2;
            if (sleepInfo.getHasSleep()) {
            }
            m8780a(true);
            m8796e(sleepInfo.getSleepCount());
            m8798f(sleepInfo.getNonRemCount());
            m8779a(sleepInfo.getStartDate());
            m8785b(sleepInfo.getStopDate());
        }
    }
}
